import gzip
import json
import time
import sys

from re_common.baselibrary.utils.basedir import BaseDir
from re_common.baselibrary.utils.basepymongo import BasePyMongo

basemongo = BasePyMongo("mongodb://cjrw:vipdatacenter@192.168.31.166:27017/")
basemongo.use_db("collection")
basemongo.create_col("jss_w_f_panternt_page")

for file in BaseDir.get_dir_all_files(r"./file"):
    print(file)
    with gzip.open(file, 'r') as f:
        for lineb in f:
            line = lineb.decode()
            linedicts = json.loads(line)
            linedicts["types"] = "jsswfpantentpage"
            starttime = time.time()
            print(linedicts)
            print(basemongo.find({"cid": linedicts["cid"], "pagenum": linedicts["pagenum"], "types": "jsswfpantentpage"})[0])
            print(time.time() - starttime)
            sys.exit(-1)
            if bools:
                print(r.text)
            else:
                print(linedicts)
                print("出错**************")
                BaseFile.single_add_file("./err.txt", data + "\n")